// import { useState, useEffect } from 'react'
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
import { getDynamicRoutes } from "./modules/DynamicRoutes.tsx";
import staticRoutes from "./modules/staticRouter.tsx";

// import testList from "@/utils/authRouteList.ts"; // 本地测试菜单权限
import testList from "@/utils/mockMenu.ts"; // 本地测试菜单权限

const RouterProvicer: React.FC = () => {
  // 1.执行登录逻辑,获取用户的菜单权限或按钮权限
  const menuList = [...testList];

  // 2.将菜单权限转换为react-router需要的路由结构
  const dynamicRoutes = getDynamicRoutes(menuList);

  // 3.合并静态路由和动态路由
  const allRouteList = [...staticRoutes, ...dynamicRoutes] as RouteObject[];
  console.log(allRouteList);

  // 4.创建react-router路由管理对象
  const routerMode = createBrowserRouter(allRouteList);

  // 5.将路由管理对象传递给RouterProvider组件
  return <RouterProvider router={routerMode}></RouterProvider>;
};

export default RouterProvicer;
